<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加用户</title>
<link href='${_resources}css/bootstrap.min.css' type='text/css' rel='stylesheet' />
<link href='${_resources}css/bootstrap-table.min.css' type='text/css' rel='stylesheet' />
<%@ include file="/WEB-INF/jsp/common/inc.jsp" %>
<script type="text/javascript" src="${_resources}JSON-js-master/json2.js"></script>
<script type="text/javascript" >
var userIdNameMap;
$.ajax({
	type: "POST",
	url: '${_baseUrl}/userController/getUserIdName',
	dataType: "json",
	async : false,
	success: function(result){
		userIdNameMap = result;
	},
	error : function (XMLHttpRequest, textStatus, errorThrown) {
	}
});


$(function (){	
	$("#user").validationEngine({
		autoHidePrompt:true,//自动隐藏
		showOnMouseOver:true,//当鼠标移出时触发
		promptPosition:'bottomLeft',//提示信息的位置
		inlineValidation: true,//是否即时验证，false为提交表单时验证,默认true  
		failure : function() {
		    layer.message("验证失败，请检查");
			return false;  
		},//验证失败时调用的函数
		ajaxFormValidation: true,//开始AJAX验证
		success : function() {
		//	$("#addForm").submit();
		}//验证通过时调用的函数 
		//onAjaxFormComplete: ajaxValidationCallback
	});

	var path = ""
	if("${customCode}" =="tianjin712suo"){
		path = '${_baseUrl}/departTianSevenController/getParentId'
	} else {
		path = '${_baseUrl}/departmentController/getParentId'
	}
	$.ajax({
		cache:false,
		async:false,
		type:"POST",
		url:path,
		dataType:"json",
		success: function(data){
			var obj=JSON.stringify(data);
			var innerHtml="<select style='width:100%' id='departId' name='departId' class='qr_select'><option value=''>请选择</option>";
			if(obj=="[]"){
				innerHtml+=""; 
			}else{
				innerHtml+="";    
				for(var i=0;i<data.length;i++){	
						innerHtml+="<option value='"+data[i].id+"'>"+data[i].deptName+"</option>";    
				}  
			}
			innerHtml+="</select>";                  
			$("#depart").html(innerHtml);
		}
	});

	$("#submit").click(function (){
		if($("#user").validationEngine('validate')){
			var userId=$("#userId").val();
			var userName=$("#userName").val();
			var password=$("#password").val();
			var confirmPwd=$("#confirmPwd").val();
			
			if("${customCode}" != "tianjin712suo"){
				var re = new RegExp(/^[a-zA-Z0-9]$/);       // ^表示开始  $表示结束
				var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>《》/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]");
				if(pattern.test(password)){
					 layer.msg("密码必须为数字或字母！",{shift:5,time:2500});
		                $("#password").focus();
		                return false;
				}
	            if (re.test(password)){
	            	alert(password);
	                layer.msg("密码必须为数字或字母！");
	                $("#password").focus();
	                return false;
	            }
			}else{
				//至少8个字符，至少1个大写字母，1个小写字母，1个数字和1个特殊字符
				var pwdReg = new RegExp(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}/);
				if(!pwdReg.test(password)){
					layer.msg("密码至少8个字符，大小写混合，包含数字和特殊字符");
					$("#password").val("");
					var confirmPwd=$("#confirmPwd").val("");
					return false;
				}
			}						
			for(var i=0; i<userIdNameMap.length; i++){
				if (userIdNameMap[i].userId == userId) {
					layer.msg("用户账号已存在！");    /* 更改提示语  */
					return false;
				}
			}
			if(password!=confirmPwd){
				layer.msg("两次密码不相同！");
				return false;
			}
			//
			
			var options = {
					dataType:"json",
					success:function(json){
						if(json.code == '1'){
							layer.msg(json.message,{shift:5},function(){
								parent.refreshTable();
								parent.closeWin();
							});
						}
						if(json.code == '0'){
							layer.msg(json.message);
						}
					},
					error:function(json){
						layer.msg("系统错误,请联系管理员");
					}
				};
				$('#user').ajaxSubmit(options);
			
		}
		
	});
	$("#close").click(function (){
		parent.refreshTable();
		parent.closeWin();
	});
	
	//将密码至为空
	$("#password").val("");
	
	

})

function onPassWord(){
		var val = $("#uesrRankId").val();
		if(val != null && val != ""){
			var safeListJson = '${safeListJson}';
			var trJson = eval('('+safeListJson+')');
			for(var i = 0 ; i < trJson.length ; i++){
				if(trJson[i].id == val){
					var pwdMinLength = trJson[i].minimumPwdLength;
					var pwdMaxLength = trJson[i].maximumPwdLength;
					$("#password").attr("class","validate[required,minSize["+pwdMinLength+"],maxSize["+pwdMaxLength+"],custom[passwordRule]] jbxinxi_input")
				}
			}
		}/* else{
			$("#password").val("");
			layer.msg("请先选择用户密级");
		} */
	}
	
	
</script>
<style type="text/css">
.table tbody > tr > td{vertical-align: middle;}
</style>
</head>
<body>
<form name="user" id="user" action="${_baseUrl}/userController/add" method="post">  
    <input type="hidden" id="isSys" name="isSys" value="0"> 
	<table class="table table-bordered ofo submenu_table" style="margin-top:10px">
		<tr>
			<td height="50" width="15%" align="center" valign="middle"><span style="color: #f00">*</span>用户账号</td>
			<td width="35%" valign="middle"><div class=""><input type="text" name="userId" id="userId" class="validate[required,maxSize[25],custom[onlyGeneralCharacter]] nav_input" placeholder="请输入..."></div></td>
			<td width="15%" valign="middle" align="center"><span style="color: #f00">*</span>员工编码</td>
			<td width="35%" valign="middle"><div class=""><input type="text" value="${userNumber }" name="userNumber" id="userNumber" class="validate[required,maxSize[20]] nav_input" placeholder="请输入..."></div></td>
		</tr>
		<tr>
			<td height="50" width="15%" align="center"><span style="color: #f00">*</span>密&emsp;&emsp;码</td>
			<td width="35%" valign="middle">
				<div class="jbxinxi_s">
	        		<input type="password" onpaste="return false" name="password"  id="password" placeholder="请输入..." 
	        		       <c:if test="${numCode ne 'tianjin712suo'}">
	        		       	 class="validate[required,minSize[${pwdMinLength }],maxSize[${pwdMaxLength }],custom[passwordRule]] nav_input"
	        		       </c:if>
	        		       <c:if test="${customCode eq 'tianjin712suo'}">
	        		         class="validate[required,custom[highPassword]] nav_input"
	        		         onfocus="onPassWord()" 
	        		       </c:if>
	        		>
	        	</div>
	        	<div class="password-meter">
					<div class="password-meter-message"></div>
					<div class="password-meter-bg">
						<div class="password-meter-bar"></div>
					</div>
				</div>
			</td>
			<td width="15%" valign="middle" align="center"><span style="color: #f00">*</span>确认密码</td>
			<td width="35%" valign="middle"><div class=""><input type="password" name="confirmPwd"  id="confirmPwd" class="validate[required,equals[password]] nav_input" placeholder="请输入..."></div></td>
		</tr>
		<tr>
			<td><span style="color: #f00">*</span>姓&emsp;&emsp;名</td>
			<td><div class=""><input type="text" name="userName" id="userName" class="validate[required,maxSize[25]] nav_input" placeholder="请输入..."></div></td>
			<td>身份证号码</td>
			<td><div class=""><input type="text" name="idCard" id="idCard" class="jbxinxi_input validate[custom[chinaIdLoose]] nav_input" placeholder="请输入..."></div></td>
		</tr>
		<tr>
			<td>电子邮箱</td>
			<td><div class=""><input type="text" name="email" id="email"   class="validate[custom[email],maxSize[100]] nav_input" placeholder="请输入..."></div></td>
			<td>所属部门</td>
			<td>
				<div class="qr_input">
	        		<span id="depart" ></span>
	        	</div>
	        </td>
		</tr>
		<tr>
			<td>性&emsp;&emsp;别</td>
			<td>
				<div class="radio_a">
				        <input class="radio_a_input" id="item1" type="radio" name="sex" value="0" checked>
				        <label class="radio_a_label" for="item1"></label>
				        <span style="margin-left: 10px">男</span>
				 </div>
				 <div class="radio_a" style="margin-left:30px">
				        <input class="radio_a_input" id="item2" type="radio" name="sex" value="1">
				        <label class="radio_a_label" for="item2"></label>
				        <span style="margin-left: 10px">女</span>
				</div>
		    </td>
			<td>手&emsp;&emsp;机</td>
			<td><div class=""><input type="text" name="mobilePhone" id="mobilePhone" class="validate[custom[mobile]] nav_input" placeholder="请输入..."></div></td>
		</tr>
		<tr>
			<td>办公电话</td>
			<td><div class=""><input type="text" name="officeTelephone" id="officeTelephone" class="validate[maxSize[50],minSize[2],custom[onlyGeneralCharacter]] nav_input" placeholder="请输入..."></div></td>
			<td>家庭电话</td>
			<td><div class=""><input type="text" name="homePhone" id="homePhone" class="validate[maxSize[50],minSize[2],custom[onlyGeneralCharacter]] nav_input" placeholder="请输入..."></div></td>
		</tr>
		<tr>
			<td>职&emsp;&emsp;务</td>
			<td><div class=""><input type="text" name="post" id="post" class="validate[maxSize[50]]  nav_input" placeholder="请输入..."></div></td>
			<c:if test="${sysPwdLevel eq 'user'}">
			<td><span style="color: #f00">*</span>用户密级</td>
			<td><div class="qr_input">
	        		<span id="" >
	        		   <select id='uesrRankId' name='uesrRankId' class='validate[required] qr_select' style="width:100%">
	        		   	    <option value=''>请选择</option>
	        		   	    <c:forEach items="${safeList}"  var="safe">
	        		   	        <option value='${safe.id}'>${safe.systemLevelName}</option>
	        		   	    </c:forEach>
	        		   </select>
	        		</span>
	        	</div> 
	        </td>
	        </c:if>
	        <c:if test="${sysPwdLevel ne 'user'}">
			<td></td>
			<td></td>
	        </c:if>
		</tr>
	</table>
<div class="permission_an mubanclass_an ma mt20">
	<shiro:hasPermission name="userController:add">
       <a href="javascript:;" class="per_baocun" id="submit">保存</a>
    </shiro:hasPermission>
	<shiro:hasPermission name="userController:close3">
    	<a href="javascript:;" class="per_gbi" id="close">关闭</a>
    </shiro:hasPermission>
</div>
</form>
</body>
<script type="text/javascript">
$(function(){
	clearBlank();
})
function clearBlank(){
	var obj = $("td");
	for(var i = 0; i<obj.length; i++){
		if(i%2 == 0){
			obj.eq(i).each(function(){
				var str = $(this).html();
				console.log(str);
				$(this).css({'text-align':'center'});
			})
		}
	}
}
</script>
</html>
